#ifndef CLIENTMESSAGEMANAGER_H
#define CLIENTMESSAGEMANAGER_H

#include "clientconnection.h"
#include <QStringList>
#include <QList>

class ClientMessageManager : public QObject
{
    Q_OBJECT
public:
    explicit ClientMessageManager(QObject *parent = 0);
    ~ClientMessageManager();
    //function for connection to Host
    void connectToSocket(QString _ip, int _port);
    //function for disconnecting from Host
    //  ClientManager must send CS_DISCONNECT before disconnecting from host
    void disconnectFromSocket();
    bool connected();

public slots:
    //slots for catching signals from ClientConnection
    //  about connection
    void slotConnectionSuccessfull();
    void slotConnectionError(QAbstractSocket::SocketError err);
    void slotDisconnectedFromSocket();

    //slot for catching signal from ClientConnection
    //  about receiving message
    void slotReceivedCommand(QString str);

    //slots for catching signals from ClientManager
    //  about Commands(agreed to protocol) to send to Host
    void slotSEND_NICK(QString nickname);
    void slotDISCONNECT();
    void slotFIRE();
    void slotMOVE();
    void slotTURN(char turnDirection);
    void slotSTOP_MOVE();
    void slotSTOP_FIRE();

signals:
    //signals for ClientManager about connections
    void signalConnectionSuccessfull();
    void signalDisconnectedFromSocket();
    void signalConnectionError(QAbstractSocket::SocketError err);

    //signals from ClientMessageManager::parseToCommand to ClientManager
    //  about received from Host message (agreed to protocol)
    void signalSC_CONN_ACCEPTED(int playerId);
    void signalSC_CONN_REJECTED(QString message);
    void signalSC_PLAYERLIST(QStringList);
    void signalSC_GAME_START();
    void signalSC_GAME_END(int playerId);

    void signalSC_MOVE(int playerId);
    void signalSC_FIRE(int playerId);
    void signalSC_TURN(int playerId, char direction);
    void signalSC_STOP_MOVE(int playerId);
    void signalSC_STOP_FIRE(int playerId);

    void signalSC_SEND_MAP(int width, int height, const QString& map, int health,
                           int motion_speed, int bullet_speed, int fire_rate);

    void signalSC_START_SNAPSHOT();
    void signalSC_SET_TANK(int tank_id, int health, int pos_x, int pos_y,
                           char action, char direction, int progress);
    void signalSC_SET_BULLET(int bullet_id, int pos_x, int pos_y,
                             char direction, int progress);
    void signalSC_END_SNAPSHOT();

    void signalUNKNOWN_COMMAND(QString str);

private:
    ClientConnection *clientConnection;
    void parseToCommand(QString str);

};

#endif // CLIENTMESSAGEMANAGER_H
